package com.jkc.xh.models;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 * Created by zhangbreeze on 15/11/17.
 */
public class HaltSellModel implements Serializable {
    public String haltsell_id;
    public String stock_code;
    public String stock_name;
    public String sell_price;
    public String cansell_amount;
    public String min_amount;
    public String rate_bal;

    public long nowInputCount = 100;

    public String getBalMoney(long buyNum) {
        BigDecimal price = new BigDecimal(sell_price);
        BigDecimal rate = new BigDecimal(rate_bal);
        BigDecimal count = new BigDecimal(buyNum);

        BigDecimal moneyTmp = price.multiply(rate).multiply(count);
        String money = moneyTmp.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "";
        nowInputCount = buyNum;
        return money;
    }

    public long getIllegleNum(long nowCount) {
        long max = Long.valueOf(cansell_amount);
        long min = Long.valueOf(min_amount);
        if (nowCount > max) {
            nowCount = max;
        }
        if (nowCount < min) {
            nowCount = min;
        }
        nowCount = nowCount - (nowCount % 100);
        nowInputCount = nowCount;
        return nowCount;
    }

    public boolean isIllegleNum() {
        long max = Long.valueOf(cansell_amount);
        long min = Long.valueOf(100);
        if (nowInputCount > max) {
            return false;
        }
        if (nowInputCount < min) {
            return false;
        }
        return true;
    }
    /*
        "haltsell_id" : "自动委托编号",
        "stock_code" : "证券代码",
        "stock_name" : "名称",
        "sell_price" : "价格",
        "cansell_amount" : "最大可买数量，用户买入的数量不能大于该值",
        "min_amount" : "最少买入数量，用户买入的数量不能小于该值，且必须为100整数倍",
        "rate_bal" : "保证金比例。客户端显示保证金的公式为=买入数量*sell_price*rate_bal"
    * */
}
